package com.ty.user.starter.controller;


import com.ty.user.starter.entity.dto.ChangPwdDto;
import com.ty.user.starter.entity.dto.UserDto;
import com.ty.user.starter.exception.UserMgtException;
import com.ty.user.starter.service.UserService;
import com.ty.user.starter.util.R;
import com.ty.user.starter.util.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author minku
 * @since 2021-10-15
 */
@Slf4j
@Api(tags = {"用户管理"})
@RestController
@RequestMapping("/mgt/user")
public class UserController {

    private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    @ApiOperation("新增")
    @PostMapping("add")
    public R<String> add(@Valid @ModelAttribute  UserDto dto) throws UserMgtException {
        userService.add(dto);
        return ResponseUtil.success(null);
    }

    @ApiOperation("修改密码")
    @PutMapping("change-pwd")
    public R<String> changePwd(@Valid @ModelAttribute ChangPwdDto dto) throws UserMgtException {
        userService.changPwd(dto);
        return ResponseUtil.success(null);
    }
}
